package com.crx.springbootinit.controller.admin;

import com.crx.springbootinit.annotation.AuthCheck;
import com.crx.springbootinit.annotation.LogApiAnno;
import com.crx.springbootinit.common.BaseResponse;
import com.crx.springbootinit.model.dto.page.PageVO;
import com.crx.springbootinit.model.dto.user.UserEnableDTO;
import com.crx.springbootinit.model.dto.user.UserPageDTO;
import com.crx.springbootinit.model.vo.user.UserPageVO;
import com.crx.springbootinit.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 谢杭延
 * @Date 2024-11-01 13:02
 */
@RestController
@RequestMapping("/admin/user")
@Api(tags = "用户模块接口")
public class UserAdminController {
    @Autowired
    private IUserService userService;
    @ApiOperation(value = "分页查询用户列表")
    @GetMapping("/page")
    @LogApiAnno(title = "用户模块", businessType = "GET")
    @AuthCheck
    public BaseResponse<PageVO<UserPageVO>> queryUserPage(UserPageDTO userPageDTO) {
        PageVO<UserPageVO> pageVO =userService.queryUserPage(userPageDTO);
        return BaseResponse.success(pageVO);
    }

    @ApiOperation(value = "删除用户")
    @DeleteMapping ("/delete/{ids}")
    @LogApiAnno(title = "用户模块", businessType = "DELETE")
    @AuthCheck
    public BaseResponse<Void> deleteUser(@ApiParam("用户id列表") @PathVariable List<Long> ids) {
        userService.removeByIds(ids);
        return BaseResponse.success();
    }

    @ApiOperation(value = "禁用启用用户")
    @PutMapping("/able")
    @LogApiAnno(title = "用户模块", businessType = "PUT")
    @AuthCheck
    public BaseResponse<Void> enableUser(@RequestBody UserEnableDTO userEnableDTO) {
        userService.enableUser(userEnableDTO);
        return BaseResponse.success();
    }
}
